package com.fzt.admin.controller;

import com.fzt.admin.common.convention.result.Result;
import com.fzt.admin.common.convention.result.Results;
import com.fzt.admin.dto.req.ShortLinkGroupSaveReqDTO;
import com.fzt.admin.dto.req.ShortLinkGroupSortReqDTO;
import com.fzt.admin.dto.req.ShortLinkGroupUpdateReqDTO;
import com.fzt.admin.dto.resp.ShortLinkGroupRespDTO;
import com.fzt.admin.service.GroupService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/*
短链接分组控制层
 */
@RestController
@RequiredArgsConstructor
public class GroupController {

    private final GroupService groupService;

    /*
    新增短链接
     */
    @PostMapping("/api/short-link/admin/v1/group")
    public Result<Void> saveGroup(@RequestBody ShortLinkGroupSaveReqDTO reqParam){
        groupService.saveGroup(reqParam);
        return Results.success();
    }

    /*
    查询短链接
     */
    @GetMapping("/api/short-link/admin/v1/group")
    public Result<List<ShortLinkGroupRespDTO>> listGroup() {
        return Results.success(groupService.listGroup());
    }

    /*
    短链接分组修改
     */
    @PutMapping("/api/short-link/admin/v1/group")
    public Result<Void> updateGroup(@RequestBody ShortLinkGroupUpdateReqDTO reqDTO){
        groupService.updateGroup(reqDTO);
        return Results.success();
    }

    /*
    删除短链接分组
     */
    @DeleteMapping("/api/short-link/admin/v1/group")
    public Result<Void> deleteGroup(@RequestParam("gid") String gid){
        groupService.deleteGroup(gid);
        return Results.success();
    }

    /*
    分组排序
     */
    @PostMapping("/api/short-link/admin/v1/group/sort")
    public Result<Void> sortGroup(@RequestBody List<ShortLinkGroupSortReqDTO> reqDTO){
        groupService.sortGroup(reqDTO);
        return Results.success();
    }
}
